package com.cgc.venus.server.ci.controller;

import com.cgc.venus.server.ci.inter.CodeSourceService;
import com.cgc.venus.server.ci.model.dao.CodeSourceDao;
import com.cgc.venus.server.ci.model.entity.CodeSource;
import com.cgc.venus.server.ci.model.vo.CodeSourceVO;
import com.cgc.venus.server.core.bean.response.VenusResponse;
import com.cgc.venus.server.core.bean.response.VenusResponseStatus;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * Created by 业哥 on 2018/11/7
 */
@Api(value = "codesource接口",description="codesource接口")
@RequestMapping("/code-source-admin")
@RestController
public class CodeSourceController {
    @Autowired
    private CodeSourceDao codeSourceDao;
    @Autowired
    private CodeSourceService codeSourceService;
    @ApiOperation("分页查询")
    @RequestMapping(value = "/codeSource", method = RequestMethod.GET)
    @ResponseBody
    public Object m1(@RequestParam("key") String key,@RequestParam("teamId") String teamId,@RequestParam("pageNum") Integer pageNum,@RequestParam("rowNum") Integer rowNum) {
        PageInfo<CodeSource> pageInfo=codeSourceService.findByKey(key,teamId,pageNum,rowNum);
        VenusResponse<PageInfo<CodeSource>> response=new VenusResponse<PageInfo<CodeSource>>(VenusResponseStatus.OK,"",pageInfo);
        return  response;
    }

    @ApiOperation("全部查询")
    @RequestMapping(value = "/codeSource/all", method = RequestMethod.GET)
    @ResponseBody
    public Object m0(@RequestParam("teamId") String teamId) {
        List<CodeSourceVO> csvs=codeSourceService.findByTeamId(teamId);
        VenusResponse<List<CodeSourceVO>> response=new VenusResponse<List<CodeSourceVO>>(VenusResponseStatus.OK,"",csvs);
        return  response;
    }

    @ApiOperation(value = "新增")
    @RequestMapping(value = "/codeSource", method = RequestMethod.POST)
    public Object m2(@RequestBody CodeSource codeSource)  {
        int row=codeSourceDao.insertCodeSource(codeSource);
        if(row>0){
            return new VenusResponse<String>(VenusResponseStatus.OK,"新增成功!","");
        }else{
            return new VenusResponse<String>(VenusResponseStatus.VENUS_EXCEPTION,"新增失败!","");
        }
    }

    @ApiOperation("修改")
    @RequestMapping(value = "/codeSource", method = RequestMethod.PATCH)
    @ResponseBody
    public Object m3(@RequestBody CodeSource codeSource) {
        int row=codeSourceDao.updateCodeSource(codeSource);
        if(row>0){
            return new VenusResponse<String>(VenusResponseStatus.OK,"修改成功!","");
        }else{
            return new VenusResponse<String>(VenusResponseStatus.VENUS_EXCEPTION,"修改失败!","");
        }
    }

    @ApiOperation("删除")
    @RequestMapping(value = "/codeSource", method = RequestMethod.DELETE)
    @ResponseBody
    public Object m4(@RequestParam("id") String id) {
        int row=codeSourceDao.deleteCodeSourceById(id);
        if(row>0){
            return new VenusResponse<String>(VenusResponseStatus.OK,"删除成功!","");
        }else{
            return new VenusResponse<String>(VenusResponseStatus.VENUS_EXCEPTION,"删除失败!","");
        }
    }
}